<template>
	<div style="padding-bottom: 180px;">
		<view v-if="!outCodePrefixStatus" style="background-color: #ffffff;margin: 10px;border-radius: 12px;padding: 15px;">
			<uni-forms ref="form" :modelValue="formData" :rules="rules" labelWidth="75px">
				<uni-forms-item label="合作项目">
					<uni-data-select v-model="formData.projectId" :localdata="projectId"
						style="background-color: white;" />
				</uni-forms-item>
				<!-- <uni-forms-item label="运单类型" name="waybillType" required>
					<uni-data-select v-model="formData.waybillType" :localdata="waybillType"
						style="background-color: white;" />
				</uni-forms-item> -->
			</uni-forms>
		</view>
		<!--收发货方-->
		<view style="background-color: #ffffff;margin: 10px;border-radius: 12px;padding: 15px 15px 25px;display: flex;flex-direction: row;">
			<view style="width: 50px;display: flex;flex-direction: column;">
				<view style="height: 24px;width: 24px;border-radius: 50%;background-color: #464646;color: #ffffff;display: flex;justify-content: center;align-items: center;">发</view>
			    <view style="height: 156px;width: 1px;border-left: 1rpx dashed #bf6006;margin-left: 11px;"></view>
				<view style="height: 24px;width: 24px;border-radius: 50%;background-color: #bf6006;color: #ffffff;display: flex;justify-content: center;align-items: center;">收</view>
			</view>
			<view style="display: flex;flex-direction: column;width: 100%;">
				<view style="display: flex;width: 100%;min-height: 160px;">
					<!--发货方-->
					<view style="display: flex;flex-direction: column;width: 100%;">
					    <text style="font-size: 16px;font-weight: bold;">发货方信息</text>
					    <span style="display: flex;justify-content: space-between;margin-top: 10px;">
							<uni-data-select :disabled="formData.orderCodeList && formData.orderCodeList.length>0" @change="selectShipId" v-model="formData.shipId" :localdata="shipId" placeholder="请选择发货方"
								style="background-color: white;width: 100%;" />
					    </span>
					    <span v-if="formData.shipContacts==''||formData.shipContacts==null" style="display: flex;margin-top: 20px;height: 37px;align-items: center;">
					    	<input disabled placeholder="请从地址簿选择发货地址" style="border: none;width: 80%;"/>
					    </span>
						<span v-else style="display: flex;flex-direction: column;margin-top: 10px;">
							<span>
								<text style="font-size: 16px;font-weight: bold;">{{formData.shipContacts}}</text>
								<text style="margin-left: 10px;">{{formData.shipContactTel}}</text>
							</span>
							<span style="font-size: 12px;color: #6f6f6f;display: -webkit-box;-webkit-box-orient: vertical;-webkit-line-clamp: 2;overflow: hidden;">
								{{formData.shipDistrictName}}{{formData.shipAddress}}
							</span>
						</span>
						<span style="display: flex;justify-content: space-between;margin-top: 10px;">
							<uni-data-select  v-model="formData.shipNetId" :localdata="shipNetId" placeholder="请选择发货网点"
								style="background-color: white;width: 100%;" />
						</span>
						
				    </view>
					<view style="display: flex;align-items: center;width: 60px;margin-top: 42px">
						<span style="display: flex;align-items: center;font-size: 14px;">
							<view style="width: 1px;height: 14px;background-color: #e7e7e7;margin-right: 5px;"></view>
							<view @click="open_shipAddress" hover-class="buttonHover" style="font-weight: bold;">地址薄</view>
						</span>
					</view>
				</view>
				<!--分割线-->
				<!-- <view style="height: 1px;width: 100%;display: flex;justify-content: center;background-color: #e7e7e7;margin: 10px 0;"></view> -->
				<view style="height: 1px;width: 100%;display: flex;justify-content: center;margin: 10px 0;"></view>
				
				<view style="display: flex;width: 100%;min-height: 160px;">
					<!--收货方-->
					<view style="display: flex;flex-direction: column;width: 100%;">
					    <text style="font-size: 16px;font-weight: bold;">收货方信息</text>
					    <span style="display: flex;justify-content: space-between;margin-top: 10px;">
					    	<uni-data-select :disabled="formData.orderCodeList && formData.orderCodeList.length>0" @change="selectDeliveryId" v-model="formData.deliveryId" :localdata="deliveryId" placeholder="请选择收货方"
					    		style="background-color: white;width: 100%;" />
					    </span>
					    <span v-if="formData.deliveryContacts==''||formData.deliveryContacts==null" style="display: flex;margin-top: 20px;height: 37px;align-items: center;">
							<input disabled placeholder="请从地址簿选择收货地址" style="border: none;width: 80%;"/>
					    </span>
						<span v-else style="display: flex;flex-direction: column;margin-top: 10px;">
							<span>
								<text style="font-size: 16px;font-weight: bold;">{{formData.deliveryContacts}}</text>
								<text style="margin-left: 10px;">{{formData.deliveryContactTel}}</text>
							</span>
							<span style="font-size: 12px;color: #6f6f6f;display: -webkit-box;-webkit-box-orient: vertical;-webkit-line-clamp: 2;overflow: hidden;">
								{{formData.deliveryDistrictName}}{{formData.deliveryAddress}}
							</span>
						</span>
						<span style="display: flex;justify-content: space-between;margin-top: 10px;">
							<uni-data-select v-model="formData.deliveryNetId" :localdata="deliveryNetId" placeholder="请选择收货网点"
								style="background-color: white;width: 100%;" />
						</span>
				    </view>
					<view style="display: flex;align-items: center;width: 60px;margin-top: 42px">
						<span style="display: flex;align-items: center;font-size: 14px;">
							<view style="width: 1px;height: 14px;background-color: #e7e7e7;margin-right: 5px;"></view>
							<view @click="open_deliveryAddress" hover-class="buttonHover" style="font-weight: bold;">地址薄</view>
						</span>
					</view>
				</view>
			</view>
			
		</view>
		<!--物品信息-->
		<view style="background-color: #ffffff;margin: 10px;border-radius: 12px;padding: 15px;">
			<view style="display: flex;justify-content: space-between;min-height: 25px;">
				<view style="flex: 1;display: flex;flex-wrap: wrap;">
					<div v-for="(item,index) in formData.orderCodeList" :key="index">
						<template>
							<uni-tag  @click="deleteOrderCodeList(index)" style="padding: 0 5px 5px 0;display: flex;" :inverted="true" :text="item.slice(0,item.indexOf('(')+1)+item.slice(-6)+' X'" type="success" />
						</template>
					</div>
				</view>
				<view @click="correlationWaybill" hover-class="buttonHover" style="display: flex;align-items: center;justify-content: center;width: 60px;height:24px;border: 1rpx solid #bf5f09;color:#bf5f09;border-radius: 4px;font-size: 12px;">
					关联订单
				</view>
			</view>
			<view style="height: 5px;"></view>
			<uni-forms :modelValue="formData" labelWidth="70px">
				<uni-forms-item label="物品信息" required>
					<view style="display: flex;justify-content: space-between;width: 100%;padding-top: 8px;">
						<view  v-if="spread" style="flex: 1;">
							<text @click="spreadAndShrink" v-if="formData.goodSourceList.length>0">{{formData.goodSourceList[0].goodsName}}，{{formData.goodSourceList[0].weight||'0'}}吨，{{formData.goodSourceList[0].bulk||'0'}}立方米，{{formData.goodSourceList[0].num||'0'}}件</text>
							<text v-else>请添加物品</text>
						</view>
						<view v-else style="display: flex;flex-direction: column;flex: 1;">
							<span v-for="(item,index) in formData.goodSourceList" :key="index" style="display: flex;align-items: center;margin-bottom: 10px;background-color: #f7f6f6;padding: 4px;font-size: 12px;">
								<view @click="editGoodsList(index)" hover-class="buttonHover" style="flex: 2;">{{item.goodsName}}，{{item.weight||'0'}}吨，{{item.bulk||'0'}}立方米，{{item.num||'0'}}件</view>
								<!-- <view style="flex: 1;display: flex;">
									<view @click="editGoodsList(index)" hover-class="buttonHover"><uni-icons type="compose" size="18" color="#bf5f09"></uni-icons></uni-icons></view>
									<view @click="deleteGoodsList(index)" hover-class="buttonHover" style="margin-left: 10px;"><uni-icons type="trash" size="18" color="#bf5f09"></uni-icons></view>
								</view> -->
								<view v-if="item.pickupOrderNo===undefined" style="display: flex;">
									<!-- <view @click="editGoodsList(index)" hover-class="buttonHover"><uni-icons type="compose" size="18" color="#bf5f09"></uni-icons></uni-icons></view> -->
									<view @click="deleteGoodsList(index)" hover-class="buttonHover" style="margin-left: 10px;"><uni-icons type="trash" size="18" color="#bf5f09"></uni-icons></view>
								</view>
							</span>
						</view>
						<view style="display: flex;justify-content: flex-end;width: 112px;">
							<view  @click="spreadAndShrink" style="color: #464646;">
								<span v-if="spread" style="display: flex;align-items: center;">
									<view style="background-color: #bf6006;color: #ffffff;border-radius: 50%;display: flex;justify-content: center;align-items: center;width: 18px;height: 18px;">
										{{formData.goodSourceList.length}}
									</view>
									展开<uni-icons type="bottom" size="14" color="#464646"></uni-icons>
								</span>
								<span v-else>
									隐藏<uni-icons type="top" size="14" color="#464646"></uni-icons>
								</span>
							</view>
							<view @click="addGoods" hover-class="buttonHover" style="color: #bf6006;margin-left: 10px;">添加<uni-icons type="plusempty" size="14" color="#bf6006"></uni-icons></view>
						</view>
					</view>
				</uni-forms-item>
				<uni-forms-item label="出库单" name="file">
					<myfilepicker :limit="'2'"  :fileIdString="formData.outboundAttach" :fileExtname="'pdf,png,gif,jpg,jpeg,doc,docx'" :fileMediatype="'all'"  @transFileIdString="getFileIdString_outboundAttach"
							:title="'*点击上传出库单，支持pdf/doc/docx/jpg/jpeg/png/gif，最多可上传2个附件*'"></myfilepicker>
				</uni-forms-item>
				<uni-forms-item label="运单附件" name="file">
					<myfilepicker :limit="'3'"  :fileIdString="formData.billAttach" :fileExtname="'pdf,png,gif,jpg,jpeg,doc,docx'" :fileMediatype="'all'"  @transFileIdString="getFileIdString_billAttach"
							:title="'*点击上传运单附件，支持pdf/doc/docx/jpg/jpeg/png/gif，最多可上传3个附件*'"></myfilepicker>
				</uni-forms-item>
				<view style="display: flex;">
					<view style="flex: 1;margin-right: 5px;">
						<uni-forms-item label="总包装费"  name="totalPackingFee">
							<uni-easyinput type="text" disabled v-model="formData.totalPackingFee" placeholder="总包装费" />
						</uni-forms-item>
					</view>
					<view style="flex: 1;">
						<uni-forms-item label="里程运费" labelAlign="right" name="totalMileageFee">
							<uni-easyinput type="text" v-model="formData.totalMileageFee" placeholder="里程运费" />
						</uni-forms-item>
					</view>
				</view>
				<uni-forms-item label="总运费"  name="totalCarriageFee">
					<uni-easyinput type="text" disabled v-model="formData.totalCarriageFee" placeholder="总运费" />
				</uni-forms-item>
			</uni-forms>
		</view>
		<!--运送时效要求-->
		<view style="background-color: #ffffff;margin: 10px;border-radius: 12px;padding: 15px;">
			<uni-forms ref="form" :modelValue="formData"  labelWidth="96px">
				<!-- <uni-forms-item label="运送时效要求" name="deliveryTimeReq">
					<view style="display: flex;justify-content: space-between;">
						<uni-data-checkbox mode="tag" v-model="formData.deliveryTimeReq" selectedColor="#bf5f09" selectedTextColor="white" :localdata="deliveryTimeReq"></uni-data-checkbox>
						<checkbox-group style="padding-top: 8px;" @change="checkboxChange">
							<label>
								<checkbox value="1" :checked="formData.cargoControl=='1'" />控货
							</label>
						</checkbox-group>
					</view>
				</uni-forms-item> -->
				<uni-forms-item label="是否控货" name="cargoControl">
					<checkbox-group style="padding-top: 8px;" @change="checkboxChange">
						<label>
							<checkbox value="1" :checked="formData.cargoControl=='1'" />控货
						</label>
					</checkbox-group>
				</uni-forms-item>
				<uni-forms-item label="计划提货时间" name="shipPlanTime" required>
					<uni-datetime-picker @change="onStartTime" :start="getNowDateTime" hide-second type="datetime" v-model="formData.shipPlanTime" />
				</uni-forms-item>
				<uni-forms-item label="发货提货方式"  name="shipPickUpWay">
					<uni-data-select  v-model="formData.shipPickUpWay" :localdata="shipPickUpWay"
						style="background-color: white;" />
					<view style="margin-top: 20px;">
						<uni-easyinput type="number" v-model="formData.shipPickUpFee" placeholder="提货费" />
					</view>
				</uni-forms-item>
				<!-- <uni-forms-item label="预约时间">
					<uni-datetime-picker type="datetime" v-model="formData.shipAppointmentTime" />
				</uni-forms-item> -->
				<uni-forms-item label="计划到达时间" name="deliveryPlanTime" required>
					<uni-datetime-picker :start="getTowHourDateTime" hide-second type="datetime" v-model="formData.deliveryPlanTime" />
				</uni-forms-item>
				<uni-forms-item label="到达提货方式"  name="deliveryPickUpWay">
					<uni-data-select v-model="formData.deliveryPickUpWay" :localdata="deliveryPickUpWay"
						style="background-color: white;" />
					<view style="margin-top: 20px;">
						<uni-easyinput type="number" v-model="formData.deliveryPickUpFee" placeholder="送货费" />
					</view>
				</uni-forms-item>
				<!-- <uni-forms-item label="预约时间">
					<uni-datetime-picker type="datetime" v-model="formData.deliveryAppointmentTime" />
				</uni-forms-item> -->
			</uni-forms>
		</view>
		<!--增值服务-->
		<view style="background-color: #ffffff;margin: 10px;border-radius: 12px;padding: 15px;height: 35px;">
			<uni-forms labelWidth="75px">
				<uni-forms-item label="增值服务" >
					<uni-list-item @click="bindPickerChangeIncrementService" :border="false" :title="JSON.stringify(formData.waybillValueAdd)=='{}'?'请选择增值服务':'编辑增值服务...'" showArrow clickable  style="height: 36px;"/>
				</uni-forms-item>
			</uni-forms>
		</view>
		<!--消费抵扣-->
		<!-- <view style="background-color: #ffffff;margin: 10px;border-radius: 12px;padding: 15px;height: 35px;">
			<uni-forms labelWidth="75px">
				<uni-forms-item label="消费抵扣" >
					<picker @change="bindPickerChangeConsumeDeduction" :value="index_consumeDeduction" :range="array_consumeDeduction">
						<uni-list-item  :border="false" :title="formData.consumeDeduction" showArrow  style="height: 36px;"/>
					</picker>
					
				</uni-forms-item>
			</uni-forms>
		</view> -->
		<!--结算方式-->
		<view style="background-color: #ffffff;margin: 10px;border-radius: 12px;padding: 15px;">
			<uni-forms  :modelValue="waybillFee" labelWidth="75px">
				<uni-forms-item label="结算方式" name="settlementMode" required>
					<uni-data-select v-model="waybillFee.settlementMode" :localdata="settlementMode"
						style="background-color: white;" />
					<view style="margin-top: 20px;">
						<!--现付-->
						<!-- <span style="display: flex;align-items: center;"
							v-if="waybillFee.settlementMode=='1'">
							<view style="flex: 2;">
								<uni-easyinput type="text" v-model="waybillFee.cod"
									placeholder="现付金额" />
							</view>
							<view style="flex: 1;margin-left: 5px;">/元</view>
						</span> -->
						<!--到付-->
						<!-- <span style="display: flex;align-items: center;"
							v-if="waybillFee.settlementMode=='2'">
							<view style="flex: 2;">
								<uni-easyinput type="text" v-model="waybillFee.pod"
									placeholder="到付金额" />
							</view>
							<view style="flex: 1;margin-left: 5px;">/元</view>
						</span> -->
						<!--欠付-->
						<!-- <span style="display: flex;align-items: center;"
							v-if="waybillFee.settlementMode=='3'">
							<view style="flex: 2;">
								<uni-easyinput type="text" v-model="waybillFee.poa"
									placeholder="欠付金额" />
							</view>
							<view style="flex: 1;margin-left: 5px;">/元</view>
						</span> -->
						<!--回单付-->
						<!-- <span style="display: flex;align-items: center;"
							v-if="waybillFee.settlementMode=='4'">
							<view style="flex: 2;">
								<uni-easyinput type="text" v-model="waybillFee.pom"
									placeholder="回单付金额" />
							</view>
							<view style="flex: 1;margin-left: 5px;">/元</view>
						</span> -->
						<!--月付-->
						<span style="display: flex;align-items: center;"
							v-if="waybillFee.settlementMode=='5'">
							<!-- <view style="flex: 1;">
								<uni-easyinput type="text" v-model="waybillFee.ms"
									placeholder="月付金额" />
							</view> -->
							<view style="flex: 1;">
								<uni-combox :candidates="payType_day" placeholder="请选择天数"
									v-model="waybillFee.msDay"></uni-combox>
							</view>
						</span>
						<!--混合付-->
						<!-- <span style="display: flex;flex-direction: column;"
							v-else-if="waybillFee.settlementMode=='7'">
							<span style="display: flex;align-items: center;">
								<view style="flex: 2;">
									<uni-easyinput type="text" v-model="waybillFee.cod"
										placeholder="现付" />
								</view>
								<view style="flex: 1;margin-left: 5px;">/元</view>
				
								<view style="flex: 2;">
									<uni-easyinput type="text" v-model="waybillFee.pod"
										placeholder="到付" />
								</view>
								<view style="flex: 1;margin-left: 5px;">/元</view>
							</span>
							<span style="display: flex;align-items: center;margin-top: 20px;">
								<view style="flex: 2;">
									<uni-easyinput type="text" v-model="waybillFee.poa"
										placeholder="欠付" />
								</view>
								<view style="flex: 1;margin-left: 5px;">/元</view>
				
								<view style="flex: 2;">
									<uni-easyinput type="text" v-model="waybillFee.pom"
										placeholder="回单付" />
								</view>
								<view style="flex: 1;margin-left: 5px;">/元</view>
							</span>
							<span style="display: flex;align-items: center;margin-top: 20px;">
								<view style="flex: 1;">
									<uni-easyinput type="text" v-model="waybillFee.ms"
										placeholder="月结金额" />
								</view>
								<view style="flex: 1;margin-left: 5px;">
									<uni-combox :candidates="payType_day" placeholder="请选择天数"
										v-model="waybillFee.msDay"></uni-combox>
								</view>
							</span>
						</span> -->
					</view>
				</uni-forms-item>
			</uni-forms>
		</view>
		<!--经办人&联系电话-->
		<view style="background-color: #ffffff;margin: 10px;border-radius: 12px;padding: 15px;">
			<uni-forms ref="form" :modelValue="formData.waybillCarrier" labelWidth="75px">
				<uni-forms-item label="经办人">
					<uni-easyinput type="text" v-model="formData.waybillCarrier.agent" placeholder="经办人" />
				</uni-forms-item>
				<uni-forms-item label="联系电话">
					<uni-easyinput type="text" v-model="formData.waybillCarrier.tel" placeholder="联系电话" />
				</uni-forms-item>
			</uni-forms>
		</view>
		<!--运价说明-->
		<view v-if="!moreSetting" style="background-color: #ffffff;margin: 10px;border-radius: 12px;padding: 15px;height: 35px;">
			<uni-forms ref="form" :modelValue="formData" labelWidth="75px">
				<uni-forms-item label="运价说明">
					<view style="display: flex;justify-content: space-between;">
						<uni-icons @click="tips" type="help" size="20" color="#999" style="padding-top: 8px;"></uni-icons>
						<view @click="clickMoreSetting(true)" hover-class="buttonHover" style="padding-top: 8px;color: #bf6006;">
							更多设置
						</view>
					</view>
				</uni-forms-item>
			</uni-forms>
		</view>
		<!--更多设置-->
		<view v-else style="background-color: #ffffff;margin: 10px;border-radius: 12px;padding: 15px;">
			<uni-forms ref="form" :modelValue="formData.waybillCarrier" labelWidth="75px">
				<view style="display: flex;">
					<view style="margin-right: 30px;">
						<checkbox-group style="padding-top: 8px;" @change="carrierObjectFlag=!carrierObjectFlag">
							<label>
								<checkbox :value="false" :checked="carrierObjectFlag" />设置承运商
							</label>
						</checkbox-group>
					</view>
					<view style="flex: 1;margin-right: 5px;">
						<uni-forms-item label="承运方" style="width: 90%;" labelWidth="55px">
							<uni-data-select :disabled="!carrierObjectFlag" v-model="formData.waybillCarrier.carrierObjectId" :localdata="carrierObjectId"
								style="background-color: white;" />
						</uni-forms-item>
					</view>
				</view>
				<uni-forms-item label="司机姓名" required>
					<uni-combox @input="inpuTdriverName" v-model="formData.waybillCarrier.driverName" :candidates="driverName" placeholder="输入检索司机"></uni-combox>
					<!-- <uni-easyinput type="text" v-model="formData.waybillCarrier.driverName" placeholder="司机姓名" /> -->
				</uni-forms-item>
				<uni-forms-item label="身份证号" required>
					<uni-combox @input="inpuIdriverCardId" v-model="formData.waybillCarrier.driverCardId" :candidates="driverCardId" placeholder="输入检索司机身份证号"></uni-combox>
					<!-- <uni-easyinput type="text" v-model="formData.waybillCarrier.driverCardId" placeholder="身份证号" /> -->
				</uni-forms-item>
				<uni-forms-item label="司机电话" required>
					<uni-combox @input="inpuTdriverCardTel" v-model="formData.waybillCarrier.driverCardTel" :candidates="driverCardTel" placeholder="输入检索司机联系电话"></uni-combox>
					<!-- <uni-easyinput type="number" v-model="formData.waybillCarrier.driverCardTel" placeholder="司机电话" /> -->
				</uni-forms-item>
				<uni-forms-item label="车牌号" required>
					<uni-combox @input="inputPlateNumber" :candidates="plateNumber" placeholder="输入检索车牌号"
						v-model="formData.waybillCarrier.driverCarId"></uni-combox>
					<view v-if="carInfo.carId">
						{{carType_[carInfo.carType]}} {{carInfo.carLength}}米，行驶证号：{{carInfo.drivingLicenseNo}}
					</view>
					<!-- <uni-easyinput type="text" v-model="formData.waybillCarrier.driverCarId" placeholder="车牌号" /> -->
				</uni-forms-item>
				<uni-forms-item label="车型" required>
					<uni-data-select  v-model="formData.waybillCarrier.vehicle" :localdata="vehicle"
						style="background-color: white;" />
				</uni-forms-item>
				<uni-forms-item label="油品类型" required>
					<uni-data-select v-model="formData.waybillCarrier.energyType" :localdata="energyType"
						style="background-color: white;" />
				</uni-forms-item>
				<!-- <view v-if="scheduleList.length!=0" style="margin-top: 10px;margin-bottom: 10px;display: flex;align-items: center;">
					当前有调度车次信息，选择当前运单加入
					<button @click="openSelectScheduleList" hover-class="buttonHover" style="background-color: #2979ff;color: white;" size="mini">选择</button>
				</view>
				<view v-if="scheduleList.length!=0&&scheduleVo.scheduleNo" style="margin-bottom: 10px;font-weight: bold;">车次号：{{schedule.scheduleNo}}</view> -->
				
				
				<!-- <uni-forms-item label="挂车牌号">
					<uni-easyinput type="text" v-model="formData.waybillCarrier.driverTrailerId" placeholder="挂车牌号" />
				</uni-forms-item> -->
				<!-- <uni-forms-item label="经办人">
					<uni-easyinput type="text" v-model="formData.waybillCarrier.agent" placeholder="挂车牌号" />
				</uni-forms-item>
				<uni-forms-item label="联系电话">
					<uni-easyinput type="text" v-model="formData.waybillCarrier.tel" placeholder="联系电话" />
				</uni-forms-item> -->
				<uni-forms-item label="押运人">
					<uni-easyinput type="text" v-model="formData.escortor" placeholder="押运人" />
				</uni-forms-item>
				<uni-forms-item label="押运人电话">
					<uni-easyinput type="text" v-model="formData.escortorPhone" placeholder="押运人电话" />
				</uni-forms-item>
				<uni-forms-item label="押运人证件">
					<uni-easyinput type="text" v-model="formData.escortorIdcard" placeholder="押运人证件" />
				</uni-forms-item>
				<uni-forms-item label="备注" name="remark">
					<uni-easyinput type="textarea" v-model="formData.remark" placeholder="运单相关备注说明" />
				</uni-forms-item>
				<uni-forms-item label="运价说明">
					<view style="display: flex;justify-content: space-between;">
						<uni-icons @click="tips" type="help" size="20" color="#999" style="padding-top: 8px;"></uni-icons>
						<view @click="clickMoreSetting(false)" hover-class="buttonHover" style="padding-top: 8px;color: #bf6006;">
							收起
						</view>
					</view>
				</uni-forms-item>
			</uni-forms>
			<!-- <view @click="moreSetting=!moreSetting" hover-class="buttonHover" style="color: #bf6006;text-align: end;">
				收起
			</view> -->
		</view>
		<!--费用计算-->
		<view v-if="totalPrice!='0.00'" style="background-color: #929292;z-index: 3;width:100%;position: fixed;bottom: 80px;font-size: 14px;">
			<view style="margin: 5px 20px;">
				<text>费用计算：</text>
				<text style="color: #ffffff;">
					<text v-if="Number(formData.totalCarriageFee)">总运费{{Number(formData.totalCarriageFee).toFixed(2)}}</text>
					<text v-if="Number(formData.totalPackingFee)">+总包装费{{Number(formData.totalPackingFee).toFixed(2)}}</text>
					<text v-if="Number(formData.shipPickUpFee)">+提货费{{Number(formData.shipPickUpFee).toFixed(2)}}</text>
					<text v-if="Number(formData.deliveryPickUpFee)">+送货费{{Number(formData.deliveryPickUpFee).toFixed(2)}}</text>
					<text v-if="Number(formData.waybillValueAdd.parcelInsuranceFee)">+保价费{{Number(formData.waybillValueAdd.parcelInsuranceFee).toFixed(2)}}</text>
					<text v-if="Number(formData.waybillValueAdd.receiptFee)">+回单费{{Number(formData.waybillValueAdd.receiptFee).toFixed(2)}}</text>
					<text v-if="Number(formData.waybillValueAdd.warehouseFee)">+仓储费{{Number(formData.waybillValueAdd.warehouseFee).toFixed(2)}}</text>
					<text v-if="Number(formData.waybillValueAdd.loadingFee)">+装货费{{Number(formData.waybillValueAdd.loadingFee).toFixed(2)}}</text>
					<text v-if="Number(formData.waybillValueAdd.unloadFee)">+卸货费{{Number(formData.waybillValueAdd.unloadFee).toFixed(2)}}</text>
					<text v-if="Number(formData.waybillValueAdd.drayage)">+短驳费{{Number(formData.waybillValueAdd.drayage).toFixed(2)}}</text>
					<!-- <text v-if="Number(formData.waybillValueAdd.carryFee)">+搬运费{{Number(formData.waybillValueAdd.carryFee).toFixed(2)}}</text> -->
					<text v-if="Number(formData.waybillValueAdd.otherFee)">+其他费用{{Number(formData.waybillValueAdd.otherFee).toFixed(2)}}</text>
				</text>
				<text style="margin-left: 10px;">预估总价￥{{totalPrice}}</text>
			</view>
		</view>
		<!--下单-->
		<view style="background-color: #ffffff;z-index: 3;height: 80px;width:100%;position: fixed;bottom: 0;display: flex;justify-content: center;box-shadow: 0px 0px 11px rgba(0, 0, 0, 0.1);">
			<view style="display: flex;justify-content: space-between;align-items: center;width: 90%;height: 60px">
				<view style="font-size: 15px;">
					应付总价：
					<text style="color: #fc7a7a;font-weight: bold;font-size: 18px;">￥{{totalPrice}}</text>
				</view>
				<view style="display: flex;">
					<view v-if="waybillId==''" @click="autoConfirm" hover-class="buttonHover" style="width: 70px;height: 30px;color: #bf5f09;background-color: #ffffff;border:1px solid #bf5f09;font-size: 18px;display: flex;justify-content: center;align-items: center;border-radius: 4px;margin-right: 10px;">保存</view>
					<view v-else @click="updateWayBillProfile" hover-class="buttonHover" style="width: 70px;height: 30px;color: #bf5f09;background-color: #ffffff;border:1px solid #bf5f09;font-size: 18px;display: flex;justify-content: center;align-items: center;border-radius: 4px;margin-right: 10px;">保存</view>
					<view @click="dialogToggle" hover-class="buttonHover" style="width: 70px;height: 30px;background-color: #bf5f09;color: #ffffff;font-size: 18px;display: flex;justify-content: center;align-items: center;border-radius: 4px;">下单</view>
				</view>
				<!-- <view style="width: 70px;height: 30px;background-color: #d9d9d9;color: #ffffff;font-size: 18px;display: flex;justify-content: center;align-items: center;border-radius: 4px;">下单</view> -->
			</view>
		</view>
		<!-- 运价说明弹窗 -->
		<uni-popup ref="popup" background-color="#fff">
			<view style="display: flex;width: 280px;flex-direction: column;padding: 10px;">
				<text>运输价格：常规价格方案</text>
				<text>应用范围：通用价格</text>
				<text>计费方式：重量*里程</text>
				<text>更新时间：2023-09-12 13:16:11</text>
				<text>计费标准：</text>
				<text>里程：首里程0KM~150KM 起运价2元/吨 ， 续里程150KM~200KM 1.5元/吨、200KM后 1元/吨。</text>
				<!-- <text>重量：首重0kg~5kg 2000元 ， 续重3kg~5kg 200元、续重8kg~15kg 180元。</text>
				<text>体积重量：轻泡系数 6000，首重0kg~5kg 2000元 ， 续重3kg~5kg 210元。</text> -->
			</view>
		</uni-popup>
		<!-- 下单提示窗 -->
		<uni-popup ref="alertDialog" type="dialog">
			<uni-popup-dialog type="info" cancelText="关闭" confirmText="提交" title="确认提交运单" @confirm="dialogConfirm">
				<scroll-view scroll-top="0" scroll-y="true" style="height: 200px;">
					<view style="display: flex;flex-direction: column;width: 100%;">
						<!-- <view style="display: flex;">
							<text style="width: 75px;">运单编号：</text>
							<text style="font-weight: bold;margin-left: 20px;">Y185655850</text>
						</view> -->
						<!-- <view style="display: flex;">
							<text style="width: 75px;">发货网点：</text>
							<text style="margin-left: 20px;">{{formData.deliveryDot}}</text>
						</view> -->
						<view style="display: flex;">
							<text style="width: 75px;">发货方：</text>
							<text style="margin-left: 20px;">{{formData.shipName}}</text>
						</view>
						<view style="display: flex;">
							<text style="width: 75px;">收货方：</text>
							<text style="margin-left: 20px;">{{formData.deliveryName}}</text>
						</view>
						<view style="display: flex;">
							<text style="width: 75px;">始发地：</text>
							<text style="margin-left: 20px;">{{formData.shipDistrictName}}{{formData.shipAddress}}</text>
						</view>
						<view style="display: flex;">
							<text style="width: 75px;">目的地：</text>
							<text style="margin-left: 20px;">{{formData.deliveryDistrictName}}{{formData.deliveryAddress}}</text>
						</view>
						<view style="display: flex;">
							<text style="width: 75px;">收货方联系人：</text>
							<text style="margin-left: 20px;">{{formData.deliveryContacts}}</text>
						</view>
						<view style="display: flex;">
							<text style="width: 75px;">联系电话：</text>
							<text style="margin-left: 20px;">{{formData.deliveryContactTel}}</text>
						</view>
						<view v-if="moreSetting">
							<view style="display: flex;">
								<text style="width: 75px;">承运商：</text>
								<text style="margin-left: 20px;">经办人{{formData.waybillCarrier.agent}}</text>
							</view>
							<view style="display: flex;">
								<text style="width: 75px;">司机姓名：</text>
								<text style="margin-left: 20px;">{{formData.waybillCarrier.driverName}}</text>
							</view>
							<view style="display: flex;">
								<text style="width: 75px;">司机电话：</text>
								<text style="margin-left: 20px;">{{formData.waybillCarrier.driverCardTel}}</text>
							</view>
							<view style="display: flex;">
								<text style="width: 75px;">身份证号：</text>
								<text style="margin-left: 20px;">{{formData.waybillCarrier.driverCardId}}</text>
							</view>
							<view style="display: flex;">
								<text style="width: 75px;">车牌号：</text>
								<text style="margin-left: 20px;">{{formData.waybillCarrier.driverCarId}}</text>
							</view>
						</view>
						
					</view>
				</scroll-view>
			</uni-popup-dialog>
		</uni-popup>
		<!-- 发货地址簿弹窗 -->
		<uni-popup ref="alertDialog_address_ship" type="dialog">
			<uni-popup-dialog type="info" cancelText="关闭" confirmText="确定" title="地址薄" @confirm="dialogConfirm_address_ship">
				<scroll-view scroll-top="0" scroll-y="true" style="height: 200px;">
					<view style="display: flex;flex-direction: column;width: 100%;">
						<radio-group @change="radioChange_ship">
							<label v-for="(item, index) in addressList_ship" :key="index"
								style="display: flex;flex-direction: column;background-color: white;padding: 15px;border-bottom: 1rpx solid #ededed;">
								<view style="display: flex;">
									<text>{{item.contactName}}</text>
									<text style="margin-left: 20px;">{{item.phone}}</text>
								</view>
								<view style="position: relative;margin-top: 10px;">
									<radio :value="JSON.stringify(item)" :checked="item.id===address_ship.id"/>
									<text style="margin-left: 10px;">{{item.bookDistrictName}}{{item.bookAddress}}</text>
								</view>
							</label>
						</radio-group>
					</view>
				</scroll-view>
			</uni-popup-dialog>
		</uni-popup>
		<!-- 收货地址簿弹窗 -->
		<uni-popup ref="alertDialog_address_delivery" type="dialog">
			<uni-popup-dialog type="info" cancelText="关闭" confirmText="确定" title="地址薄" @confirm="dialogConfirm_address_delivery">
				<scroll-view scroll-top="0" scroll-y="true" style="height: 200px;">
					<view style="display: flex;flex-direction: column;width: 100%;">
						<radio-group @change="radioChange_delivery">
							<label v-for="(item, index) in addressList_delivery" :key="index"
								style="display: flex;flex-direction: column;background-color: white;padding: 15px;border-bottom: 1rpx solid #ededed;">
								<view style="display: flex;">
									<text>{{item.contactName}}</text>
									<text style="margin-left: 20px;">{{item.phone}}</text>
								</view>
								<view style="position: relative;margin-top: 10px;">
									<radio :value="JSON.stringify(item)" :checked="item.id===address_delivery.id"/>
									<text style="margin-left: 10px;">{{item.bookDistrictName}}{{item.bookAddress}}</text>
								</view>
							</label>
						</radio-group>
					</view>
				</scroll-view>
			</uni-popup-dialog>
		</uni-popup>
		<!-- 调度车次列表弹窗 -->
		<uni-popup ref="alertDialog_scheduleList" type="dialog">
			<uni-popup-dialog type="info" cancelText="关闭" confirmText="确定" title="当前调度车次" @confirm="dialogConfirm_scheduleList">
				<scroll-view scroll-top="0" scroll-y="true" style="height: 200px;">
					<view style="display: flex;flex-direction: column;width: 100%;">
						<radio-group @change="radioChange_scheduleList">
							<label v-for="(item, index) in scheduleList" :key="index"
								style="display: flex;flex-direction: column;background-color: white;padding: 15px;border-bottom: 1rpx solid #ededed;">
								<view style="display: flex;">
									<text>{{item.scheduleNo}}</text>
									<text style="margin-left: 20px;">{{scheduleStatus[item.flowStatus]}}</text>
								</view>
								<view style="position: relative;margin-top: 10px;">
									<radio :value="JSON.stringify(item)" :checked="item.scheduleId===schedule.scheduleId" :disabled="[0,410,420,430,440].includes(item.flowStatus)"/>
									<text style="margin-left: 10px;">{{item.lineVo.lineName}}</text>
								</view>
							</label>
						</radio-group>
					</view>
				</scroll-view>
			</uni-popup-dialog>
		</uni-popup>
		<CorrelationWaybill :data="formData" @correlationWaybill="getCorrelationWaybill" ref="correlationWaybill"/>
	</div>
</template>

<script>
	import {getWayBillDetails,addWayBill,updateWayBillProfile,addSchedule} from '@/api/system/waybill.js';
	import {getProjectList,getDeptList,sysOrderSetDetail} from '@/api/system/project.js';
	import {getCustomerList,} from '@/api/system/customer.js';
	import {getCarrierList,} from '@/api/system/carrier.js';
	import {pricePlanList,getPlanCalcAmountFee,getPlanCalcWeigthMultiMileFee} from '@/api/system/planPrice.js'
	import {getDriverList,getCarrierCarList,getCarrierCarDetails} from '@/api/system/driver.js';
	import {getScheduleListByDriverId,updateSchedule} from '@/api/system/dispatch.js'
	import {getDicts} from '@/api/system/dict.js'
	import myfilepicker from '@/components/uploadFile/uploadFile.vue'
	import CorrelationWaybill from '@/pages-operation/operation/addWaybill/components/correlationWaybill.vue'
	
	import Config from '@/uni_modules/Lyn4ever-gaodeRoutePlanning/lib/config.js';
	
	export default {
		components: {
			myfilepicker,
			CorrelationWaybill
		},
		data() {
			return {
				formData: {
					projectId:'',
					waybillType:'',
					shipId:'',        //发货方ID
					shipName:'',     //发货方名
					shipContacts:'', //发货方联系人
					shipContactTel:'', //发货方联系电话
					shipDistrictId:'',//发货方省市区、县ID
					shipDistrictName:'',//发货方省市区名称
					shipAddress:'',  //发货方详细地址
					shipNetId:"",   //发货方网点ID
					
					deliveryId:'',        //收货方ID
					deliveryName:'',     //收货方名
					deliveryContacts:'', //收货方联系人
					deliveryContactTel:'', //收货方联系电话
					deliveryDistrictId:'',//收货方省市区、县ID
					deliveryDistrictName:'',//收货方省市区名称
					deliveryAddress:'',  //收货方详细地址
					deliveryNetId:"",   //收货方网点ID
					
					goodSourceList:[],  //物品列表
					outboundAttach:'', //出库单
					billAttach:'',      //物品附件
					totalPackingFee:'',  //总包装费
					totalMileageFee:'',  //里程运费
					totalCarriageFee:'', //总运费
					
					deliveryTimeReq:'0',  //时效要求
					cargoControl:'',  //控货
					shipPlanTime:'',
					shipPickUpWay:'3',  //发货提货方式（发货地直达）
					shipPickUpFee:'',
					//shipAppointmentTime:'', //发货方预约发货时间
					deliveryPlanTime:'',   //计划到达时间
					deliveryPickUpWay:'3',  //到达提货方式（收货地直达）
					deliveryPickUpFee:'',
					deliveryAppointmentTime:'', //收货方预约发货时间
					
					// goodsValue:'',   //货值声明
					// protectMoney:'', //保价费
					
					waybillValueAdd:{},  //增值服务
					//consumeDeduction:'', //消费抵扣(暂时不做)
					waybillFee:{},
					waybillCarrier:{
						carrierObjectId:'',
						driverName:'',
						driverCardId:'',
						driverCardTel:'',
						vehicle:'',
						driverCarId:'',
						driverTrailerId:'',
						agent:'',
						energyType:'',
						tel:'',
					},
					remark:'',
					goodOrderIdList:[],
					escortor:'',  //押运人
					escortorPhone:'',  //押运人电话
					escortorIdcard:''   //押运人证件
				},
				// 校验规则
				rules: {
					// waybillType: {
					// 	rules: [{
					// 		required: true,
					// 		errorMessage: '请选择运单类型',
					// 	}]
					// },
					shipPlanTime: {
						rules: [{
							required: true,
							errorMessage: '请选择计划提货时间',
						}]
					},
					deliveryPlanTime: {
						rules: [{
							required: true,
							errorMessage: '请选择计划到达时间',
						}]
					},
					totalPackingFee: {
						rules: [{
							required: true,
							errorMessage: '请输入总包装费',
						}]
					},
					totalMileageFee: {
						rules: [{
							required: true,
							errorMessage: '请输入里程运费',
						}]
					},
					totalCarriageFee: {
						rules: [{
							required: true,
							errorMessage: '请输入总运费',
						}]
					},
					deliveryTimeReq: {
						rules: [{
							required: true,
							errorMessage: '请选择运输时效',
						}]
					},
					totalCarriageFee: {
						rules: [{
							required: true,
							errorMessage: '请输入总运费',
						}]
					},
					idCardNo: {
						rules: [{
							required: true,
							errorMessage: '请输入身份证号',
						},
						{
						    pattern: '(^[1-9]\\d{5}(18|19|([23]\\d))\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$)|(^[1-9]\\d{5}\\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\\d{2}$)',
						    errorMessage: "请输入正确的身份证号"
						}
						]
					},
				},
				//承运商单选框选中状态
				carrierObjectFlag:false,
				//下拉框 ->合作项目
				projectId: [],
				//下拉框 ->运单类型
				waybillType: [],
				
				//下拉框->选择发货方
				shipId: [],
				shipCustomer:[],
				//下拉框->选择发货网点
				shipNetId: [],
				
				//下拉框->选择收货方
				deliveryId: [],
				deliveryCustomer:[],
				//下拉框->选择收货网点
				deliveryNetId: [],
				
				//回显的地址列表
				addressList_ship:[],
				addressList_delivery:[],
				
				//地址弹窗选择的地址
				address_ship:{},
				address_delivery:{},
				
				waybillFee:{
					settlementMode:'2',
					cod:'',  //现付
					pod:'',  //到付
					poa:'',  //欠付
					pom:'',  //回单付
					ms:'',//月付
					msDay:'' //月付多少天
				},
				//下拉框 ->月结多少天
				payType_day: ['7', '15', '30', '45', '60'],
				
				//物品信息是否收缩
				spread:true,
				
				//运送时效要求
				deliveryTimeReq: [{
						text: '常规',
						value: '1'
					},
					{
						text: '特快',
						value: '2'
					}
				],
				//下拉框->发货提货方式
				shipPickUpWay: [],
				//下拉框->到达提货方式
				deliveryPickUpWay: [],
				
				//选择框->选择消费抵扣
				array_consumeDeduction: ['','中国', '美国', '巴西', '日本'],
				index_consumeDeduction:0,
				
				//结算模式->下拉框
				settlementMode:[],
				
				//更多设置
				moreSetting:false,
				//承运方->下拉框
				carrierObjectId:[],
				//下拉框->司机
				driverName:[],
				//下拉框->司机身份证号
				driverCardId:[],
				//下拉框->司机电话
				driverCardTel:[],
				//所有司机集合
				allDriverList:[],
				driverJson:{},
				
				//下拉框 ->车牌号
				plateNumber: [],
				plateNumberName:'',
				plateNumberObject:[], //车辆数据
				//节流函数标志
				statu:true,
				carInfo:[],
				carJson:{},
				carType_:[],
				//车型->下拉框
				vehicle:[],
				//油品 -下拉框
				energyType:[],
				
				//车次列表
				scheduleList:[],
				//车次弹窗选择的车次
				schedule:{},
				//车次弹窗确认选择的车次
				scheduleVo:{},
				
				//车辆调度状态
				scheduleStatus:[],
				
				//运单id
				waybillId:'',
				
				//里程
				distance:'',
				//是否隐藏项目
				outCodePrefixStatus:false
			}
		},
		onLoad(e) {
			// var waybillDraft=uni.getStorageSync('waybillDraft')
			// if (waybillDraft) {
			// 	//设置顶部导航栏标题
			// 	uni.setNavigationBarTitle({
			// 		title: '新增运单-草稿'
			// 	})
				
			// 	this.formData=waybillDraft
			// 	this.waybillFee=this.formData.waybillFee
			// }
			if (e.waybillId) {
				//设置顶部导航栏标题
				uni.setNavigationBarTitle({
					title: '新增运单-草稿'
				})
				
				uni.showLoading({
					title: '正在加载',
				})
				this.waybillId=e.waybillId
				//获取运单详情
				getWayBillDetails(e.waybillId).then(res => {
					uni.hideLoading()
					if (res.code == '200') {
						this.formData = res.data
						//承运商收、放状态
						this.moreSetting=this.formData.waybillCarrier.driverName?true:false;
						//承运商单选框选中状态
						this.carrierObjectFlag=this.formData.waybillCarrier.carrierObjectId?true:false;
						this.waybillFee=this.formData.waybillFee
						this.calculate()  //计算总运费、总包装费
					} else {
						uni.showToast({
							icon: 'none',
							title: res.msg
						})
					}
				})
			}
			
			//跳转运单
			if(e.orderInfo)
			{
				//获取默认计费方式
				pricePlanList({}).then(res => {
				    const find = res.rows.find(item => item.status === '0')
				    if (!find) return
					this.formData={...this.formData,...JSON.parse(e.orderInfo)}
					this.formData={...this.formData,...this.resetTime(this.formData.shipPlanTime, this.formData.deliveryPlanTime)}
					this.formData.goodSourceList.forEach(item=>{
						item['feeMode']=find.feeMode
						item['packingService']='0'  //包装服务，默认为否'0'
					})
					this.calculateCarriageFee(find.id)
				})
				
			}
		},
		created() {
			this.getProject()
			//获取客户列表
			getCustomerList({pageNum:1,pageSize:1000}).then(res => {
				//发货方下拉数据
				this.shipId = res.rows.map(item => {
					return {
						value: item.customerId,
						customer:JSON.stringify(item),
						text: item.customerName
					}
				})
				//收货方下拉数据
				this.deliveryId = JSON.parse(JSON.stringify(this.shipId))
			})
			//加载运单类型
			getDicts('waybill_type').then(res=>{
				this.waybillType=res.data.map(item=>{
					return {
						value:item.dictValue,
						text:item.dictLabel
					}
				})
			})
			//获取部门网点
			getDeptList().then(res=>{
				//发货方
				this.shipNetId=res.data.map(item=>{
					return {
						value:item.deptId,
						text:'【'+(item.deptType==='3'?'部门':'网点')+'】'+item.deptName
					}
				})
				//收货方
				this.deliveryNetId = JSON.parse(JSON.stringify(this.shipNetId))
			})
			//获取发货提货方式下拉框
			getDicts('send_pickup_method').then(res=>{
				this.shipPickUpWay=res.data.map(item=>{
					return {
						value:item.dictValue,
						text:item.dictLabel
					}
				})
			})
			//获取到达货提货方式下拉框
			getDicts('recv_pickup_method').then(res=>{
				this.deliveryPickUpWay=res.data.map(item=>{
					return {
						value:item.dictValue,
						text:item.dictLabel
					}
				})
			})
			//获取结算模式下拉框
			getDicts('settle_type').then(res=>{
				this.settlementMode=res.data.map(item=>{
					return {
						value:item.dictValue,
						text:item.dictLabel
					}
				})
			})
			
			//获取承运方下拉框
			getCarrierList({pageNum:1,pageSize:1000}).then(res => {
				//承运方下拉框
				this.carrierObjectId = res.rows.map(item => {
					return {
						value: item.carrierId,
						text: item.carrierName+' '+item.contactPerson+' '+item.phone
					}
				})
			})
			//获取车型下拉框
			getDicts('car_type').then(res=>{
				res.data.forEach(item=>{
					this.carType_[item.dictValue]=item.dictLabel
				})
				this.vehicle=res.data.map(item=>{
					return {
						value:item.dictValue,
						text:item.dictLabel
					}
				})
			})
			//获取车牌号下拉框
			getCarrierCarList({pageNum:1,pageSize:1000}).then(res=>{
				this.plateNumber=res.rows.map(item=>{
					return item.licensePlate
				})
				this.plateNumberObject=res.rows
			})
			//获取油品下拉框
			getDicts('energy_type').then(res=>{
				this.energyType=res.data.map(item=>{
					return {
						value:item.dictValue,
						text:item.dictLabel
					}
				})
			})
			//获取司机
			getDriverList({pageNum:1,pageSize:1000}).then(res => {
				//司机下拉框
				this.allDriverList = res.rows.map(item => {
					return {
						value: item.driverId,
						text: item.driverName,
						idCardNo:item.idCardNo,
						phoneNumber:item.phoneNumber,
						plateNumberName:item.plateNumber,
						driverJson:JSON.stringify(item)
					}
				})
				this.driverName=res.rows.map(item=>{
					return item.driverName
				})
				this.driverCardId=res.rows.map(item=>{
					return item.idCardNo
				})
				this.driverCardTel=res.rows.map(item=>{
					return item.phoneNumber
				})
			})
			//加载车次调度状态
			getDicts('flow_status').then(res=>{
				res.data.forEach(item=>{
					this.scheduleStatus[item.dictValue]=item.dictLabel
				})
			})
		},
		watch: {
			'formData.totalMileageFee': {
				handler(newVal, oldVal) {
					let val=Number(newVal)-Number(oldVal);
					this.formData.totalCarriageFee=Number(this.formData.totalCarriageFee||0)+val;
				},
			},
			// 'formData.shipPickUpWay': {
			// 	handler(newVal, oldVal) {
			// 		console.log(newVal)
			// 	},
			// },
			// 'formData.deliveryPickUpWay': {
			// 	handler(newVal, oldVal) {
			// 		console.log(newVal)
			// 	},
			// },
		},
		computed: {
			totalPrice() {
				let totalCarriageFee=Number(this.formData.totalCarriageFee||0)  //总运费
				let totalPackingFee=Number(this.formData.totalPackingFee||0)    //总包装费
				let shipPickUpFee=Number(this.formData.shipPickUpFee||0)        //提货费
				let deliveryPickUpFee=Number(this.formData.deliveryPickUpFee||0) //送货费
				let parcelInsuranceFee=Number(this.formData.waybillValueAdd.parcelInsuranceFee||0) //保价费
				let receiptFee=Number(this.formData.waybillValueAdd.receiptFee||0) //回单费
				let warehouseFee=Number(this.formData.waybillValueAdd.warehouseFee||0)  //仓储费
				let loadingFee=Number(this.formData.waybillValueAdd.loadingFee||0)   //装货费
				let unloadFee=Number(this.formData.waybillValueAdd.unloadFee||0)   //卸货费
				let drayage=Number(this.formData.waybillValueAdd.drayage||0)      //短驳费
				//let carryFee=Number(this.formData.waybillValueAdd.carryFee||0)	//搬运费
				let otherFee=Number(this.formData.waybillValueAdd.otherFee||0)	//其他费用
				let totalMoney=totalCarriageFee+totalPackingFee+shipPickUpFee+deliveryPickUpFee+parcelInsuranceFee+receiptFee+warehouseFee+loadingFee+unloadFee+drayage+otherFee;
				return totalMoney.toFixed(2);
			},
			//获取当前时间
			getNowDateTime(){
				const date = new Date();
				var year = date.getFullYear();
				var month = date.getMonth()+1;
				var day = date.getDate();
				var hour = date.getHours()<10?('0'+date.getHours()):date.getHours();
				var minute = date.getMinutes()<10?('0'+date.getMinutes()):date.getMinutes();
				var second = date.getSeconds()<10?('0'+date.getSeconds()):date.getSeconds();
				return year+'-'+month+'-'+day+' '+hour+':'+minute+':'+second;
			},
			//获取当前2小时后的时间
			getTowHourDateTime(){
				const date = new Date();
				var year = date.getFullYear();
				var month = date.getMonth()+1;
				var day = date.getDate();
				var hour = (date.getHours()+2)<10?('0'+(date.getHours()+2)):(date.getHours()+2);
				var minute = date.getMinutes()<10?('0'+date.getMinutes()):date.getMinutes();
				var second = date.getSeconds()<10?('0'+date.getSeconds()):date.getSeconds();
				return year+'-'+month+'-'+day+' '+hour+':'+minute+':'+second;
			},
		},
		methods: {
			getProject(){
				//获取运单设置
				sysOrderSetDetail().then(res=>{
					this.outCodePrefixStatus = res.data.outCodePrefixStatus === 1
					if(!this.outCodePrefixStatus)
					{
						//获取合作项目下拉框
						getProjectList({pageNum:1,pageSize:1000}).then(res=>{
							this.projectId=res.rows.map(item=>{
								return {
									value:item.id,
									text:item.projectName+' '+item.leader+' '+item.phone
								}
							})
						})
					}
				})
			},
			clickMoreSetting(falg){
				this.moreSetting=falg;
				if(!falg)  //点击更多设置
				{
					//承运商单选框选中状态
					this.carrierObjectFlag=false;
					this.formData.waybillCarrier={
						carrierObjectId:'',
						driverName:'',
						driverCardId:'',
						driverCardTel:'',
						vehicle:'',
						driverCarId:'',
						driverTrailerId:'',
						agent:'',
						tel:''
					}
					this.carInfo=[]
					this.formData.remark=''
				}
			},
			//选择司机
			inpuTdriverName(e){
				if(e)
				{
					let index=this.driverName.indexOf(e)
					let diver=this.allDriverList[index]
					this.driverJson=JSON.parse(diver.driverJson);
					this.formData.waybillCarrier.driverCardId=diver.idCardNo;
					this.formData.waybillCarrier.driverCardTel=diver.phoneNumber;
					this.formData.waybillCarrier.driverCarId=diver.plateNumberName;//车牌号
					this.formData.waybillCarrier.driverId=diver.value  //司机id
					this.inputPlateNumber(diver.plateNumberName)
				}
				else
				{
					this.scheduleList=[]
				}
			},
			//选择司机身份证号
			inpuIdriverCardId(e){
				if(e)
				{
					let index=this.driverCardId.indexOf(e)
					let diver=this.allDriverList[index]
					this.driverJson=JSON.parse(diver.driverJson);
					this.formData.waybillCarrier.driverName=diver.text;
					this.formData.waybillCarrier.driverCardTel=diver.phoneNumber;
					this.formData.waybillCarrier.driverCarId=diver.plateNumberName;//车牌号
					this.formData.waybillCarrier.driverId=diver.value  //司机id
					this.inputPlateNumber(diver.plateNumberName)
				}
			},
			//选择司机电话
			inpuTdriverCardTel(e){
				if(e)
				{
					let index=this.driverCardTel.indexOf(e)
					let diver=this.allDriverList[index]
					this.driverJson=JSON.parse(diver.driverJson);
					this.formData.waybillCarrier.driverName=diver.text;
					this.formData.waybillCarrier.driverCardId=diver.idCardNo;
					this.formData.waybillCarrier.driverCarId=diver.plateNumberName;//车牌号
					this.formData.waybillCarrier.driverId=diver.value  //司机id
					this.inputPlateNumber(diver.plateNumberName)
				}
			},
			//车牌号
			inputPlateNumber(e){
				if(e)
				{
					//节流函数
					let that=this
					if(!that.statu)
					{
						return
					}
					that.statu=false
					setTimeout(()=>{
						let item=this.plateNumberObject.find(i=>i.licensePlate===e)
						if(item)
						{
							that.carInfo=item
							that.formData.waybillCarrier.vehicle=item.carType
							that.formData.waybillCarrier.energyType=item.energyType
							that.formData.waybillCarrier.carId=item.carId
						}
						else
						{
							that.carInfo=[]
							that.formData.waybillCarrier.vehicle=''
							that.formData.waybillCarrier.energyType=''
							that.formData.waybillCarrier.carId=''
						}
						// getCarrierCarDetails(e).then(res=>{
						// 	if(res.data)
						// 	{
						// 		that.carInfo=res.data
						// 		that.formData.waybillCarrier.vehicle=res.data.carType
						// 		that.formData.waybillCarrier.energyType=res.data.energyType
						// 		that.formData.waybillCarrier.carId=res.data.carId
						// 		// if(JSON.stringify(that.driverJson) != "{}")
						// 		// {
						// 		// 	getScheduleListByDriverId({driverId:that.driverJson.driverId,carId:that.carInfo.carId}).then(res=>{
						// 		// 		that.scheduleList=res
						// 		// 	})
						// 		// }
						// 	}
						// 	else
						// 	{
						// 		that.carInfo=[]
						// 		that.formData.waybillCarrier.vehicle=''
						// 		that.formData.waybillCarrier.energyType=''
						// 		that.formData.waybillCarrier.carId=''
						// 	}
							
						// })
						that.statu=true;
					},1000)
				}
				else
				{
					this.carInfo=[]
					this.scheduleList=[]
				}
			},
			//选择调度车次加入
			openSelectScheduleList(){
				this.$refs.alertDialog_scheduleList.open()
			},
			//选择车次
			radioChange_scheduleList(e) {
				//设置为车次
				this.schedule=JSON.parse(e.detail.value);
			},
			//确认设置调度车次
			dialogConfirm_scheduleList() {
				this.scheduleVo=this.schedule
			},
			//计算总运费、总包装费
			calculate(){
				let goodSourceList=JSON.parse(JSON.stringify(this.formData.goodSourceList))
				let goodSourceList_packingFee=goodSourceList.map(item=>item.packingFee)
				let goodSourceList_totalCarriageFee=goodSourceList.map(item=>item.carriageFee)
				
				//总包装费
				this.formData.totalPackingFee=goodSourceList_packingFee.reduce((a,b)=>{
					return Number(a||0)+Number(b||0);
				},0)
				//总运费
				this.formData.totalCarriageFee=goodSourceList_totalCarriageFee.reduce((a,b)=>{
					return Number(a||0)+Number(b||0);
				},0)
				
			},
			//接受保存增值服务后的数据
			otherFun_waybillValueAdd(bookList) {
				if(bookList){
					this.formData.waybillValueAdd=bookList
				}else{
					return
				}
			},
			//接受保存物品后的数据
			otherFun(bookList,index) {
				if(bookList){
					if(index)//编辑
					{
						this.formData.goodSourceList.splice(index,1,bookList)
					}
					else   //新增
					{
						this.formData.goodSourceList.push(bookList)
					}
					this.calculate()  //计算总运费、总包装费
				}else{
					return
				}
			},
			//发货方
			selectShipId(e){
				if(e)
				{
					this.formData.shipName=this.shipId.find(item=>item.value===e).text
				}
				else
				{
					this.formData.shipContacts='' 		//发货方联系人
					this.formData.shipContactTel='' 			//发货方联系电话
					this.formData.shipDistrictId=''		//发货方省市区、县ID
					this.formData.shipDistrictName=''  //发货方省市区名称
					this.formData.shipAddress='' 		//发货方详细地址
				}
				
			},
			//收货方
			selectDeliveryId(e){
				if(e)
				{
					this.formData.deliveryName=this.deliveryId.find(item=>item.value===e).text
				}
				else
				{
					this.formData.deliveryContacts=''	//收货方联系人
					this.formData.deliveryContactTel='' 		//收货方联系电话
					this.formData.deliveryDistrictId=''	//收货方省市区、县ID
					this.formData.deliveryDistrictName=''		//收货方省市区名称
					this.formData.deliveryAddress=''  		//收货方详细地址
				}
				
			},
			//打开发货方地址簿
			open_shipAddress(){
				if(this.formData.orderCodeList && this.formData.orderCodeList.length>0)
				{
					uni.showToast({
						icon:'none',
						title:'已关联订单无法修改地址'
					})
					return
				}
				//获取地址簿
				this.shipId.forEach(item=>{
					if(item.value===this.formData.shipId)
					{
						this.addressList_ship=JSON.parse(item.customer).bookList
					}
				})
				
				this.$refs.alertDialog_address_ship.open()
			},
			//打开收货方地址簿
			open_deliveryAddress(){
				if(this.formData.orderCodeList && this.formData.orderCodeList.length>0)
				{
					uni.showToast({
						icon:'none',
						title:'已关联订单无法修改地址'
					})
					return
				}
				//获取地址簿
				this.deliveryId.forEach(item=>{
					if(item.value===this.formData.deliveryId)
					{
						this.addressList_delivery=JSON.parse(item.customer).bookList
					}
				})
				this.$refs.alertDialog_address_delivery.open()
			},
			//选择地址->发货方
			radioChange_ship(e) {
				//设置为地址
				this.address_ship=JSON.parse(e.detail.value);
			},
			//选择地址->收货方
			radioChange_delivery(e) {
				//设置为地址
				this.address_delivery=JSON.parse(e.detail.value);
			},
			//确认设置地址->发货方
			dialogConfirm_address_ship() {
				this.formData.shipContacts=this.address_ship.contactName 		//发货方联系人
				this.formData.shipContactTel=this.address_ship.phone 			//发货方联系电话
				this.formData.shipDistrictId=this.address_ship.bookDistrict		//发货方省市区、县ID
				this.formData.shipDistrictName=this.address_ship.bookDistrictName//发货方省市区名称
				this.formData.shipAddress=this.address_ship.bookAddress  		//发货方详细地址
			},
			//确认设置地址->收货方
			dialogConfirm_address_delivery() {
				this.formData.deliveryContacts=this.address_delivery.contactName	//收货方联系人
				this.formData.deliveryContactTel=this.address_delivery.phone 		//收货方联系电话
				this.formData.deliveryDistrictId=this.address_delivery.bookDistrict	//收货方省市区、县ID
				this.formData.deliveryDistrictName=this.address_delivery.bookDistrictName		//收货方省市区名称
				this.formData.deliveryAddress=this.address_delivery.bookAddress  		//收货方详细地址
			},
			async getLanLatInit(){
				let startPoi=await this.getLanLat(this.formData.shipDistrictName,this.formData.shipAddress)
				let endPoi=await this.getLanLat(this.formData.deliveryDistrictName,this.formData.deliveryAddress)
				this.distance=await this.calculateMileage(startPoi,endPoi)
			},
			//根据名称获取经纬度
			getLanLat(districtName,Address){	
				return new Promise((resolve, reject) => {
					uni.request({
						 url: 'https://restapi.amap.com/v3/geocode/geo?parameters', 
						method:'GET',
						 data: {
							key: Config.GAODE_WEB_KEY,
							address:districtName+Address
						 },
						success: (res) => {
							resolve(res.data.geocodes[0].location)
						}
					}) 
				})
			},
			//计算里程
			calculateMileage(startPoi,endPoi){
				return new Promise((resolve, reject) => {
					uni.request({
						 url: 'https://restapi.amap.com/v3/direction/driving?parameters', 
						method:'GET',
						 data: {
							key: Config.GAODE_WEB_KEY,
							origin:startPoi,
							destination:endPoi
						 },
						success: (res) => {
							resolve((res.data.route.paths[0].distance)/1000)
						}
					}) 
				})
			},
			//计算单个运费的小计(计算体积、重量、数量费用费用)
			calculateCarriageFee(planId)
			{
				this.formData.goodSourceList.forEach(async item=>{
					if(item.feeMode==='weight')  //如果为重量
					{
						getPlanCalcAmountFee(planId,item.weight||0).then(res=>{
							item['carriageFee']=res.data
							//重新计算总包装费、里程运费、总运费
							this.calculate()
						})	
					}
					else if(item.feeMode==='volume') //如果为体积
					{
						getPlanCalcAmountFee(planId,item.bulk||0).then(res=>{
							item['carriageFee']=res.data
							//重新计算总包装费、里程运费、总运费
							this.calculate()
						})	
					}
					else if(item.feeMode==='weightMultiMileage') //如果为重量*里程
					{
						//计算里程
						await this.getLanLatInit()
						getPlanCalcWeigthMultiMileFee(planId,this.distance,item.weight||0).then(res=>{
							item['carriageFee']=res.data
							//重新计算总包装费、里程运费、总运费
							this.calculate()
						})	
					}
					// else if(item.feeMode==='volume') //如果为数量
					// {
					// 	getPlanCalcAmountFee(planId,item.bulk).then(res=>{
					// 		item['carriageFee']=res.data
					// 	})	
					// }
				})
			},
			//点击删除关联订单
			deleteOrderCodeList(index){
				let that = this
				uni.showModal({
					title: '提示',
					content: '确定移除此关联订单吗？',
					success: function (res) {
						if (res.confirm) {
							that.$set(that.formData,'goodSourceList',that.formData.goodSourceList.filter(item=>{
								if((item.pickupOrderNo+'('+item.orderCode+')')===that.formData.orderCodeList[index])
								{
									that.$set(that.formData,'goodOrderIdList',that.formData.goodOrderIdList.filter(i=>item.goodOrderId!=i))
								}
							  return (item.pickupOrderNo+'('+item.orderCode+')')!==that.formData.orderCodeList[index]
							}))
							that.formData.orderCodeList.splice(index, 1);
							
							//将费用清空
							if(that.formData.goodSourceList.length===0)
							{
								//总包装费
								that.formData.totalPackingFee=''
								//总运费
								that.formData.totalCarriageFee=''
							}
							//重新计算总包装费、里程运费、总运费
							that.calculate()
						}
					}
				});
			},
			//关联订单
			correlationWaybill(){
				this.$refs.correlationWaybill.correlationWaybill(this.formData.orderCodeList||[])
			},
			//获取到关联后的订单
			getCorrelationWaybill(form){
				//获取默认计费方式
				pricePlanList({}).then(async res => {
				    const find = res.rows.find(item => item.status === '0')
				    if (!find) return
					
					form.goodSourceList.forEach(item=>item['feeMode']=find.feeMode)
					let a=this.formData.goodSourceList||[]
					let b=this.formData.orderCodeList||[]
					let c=this.formData.goodOrderIdList||[]
					a.push(...form.goodSourceList)
					b.push(...form.orderCodeList)
					c.push(...form.goodOrderIdList)
					form.goodSourceList=JSON.parse(JSON.stringify(a))
					form.orderCodeList=JSON.parse(JSON.stringify(b))
					form.goodOrderIdList=JSON.parse(JSON.stringify(c))
					this.formData={...this.formData,...JSON.parse(JSON.stringify(form))}
					this.formData={...this.formData,...this.resetTime(this.formData.shipPlanTime, this.formData.deliveryPlanTime)}
					this.formData.goodSourceList.forEach(item=>{
						item['feeMode']=find.feeMode
						item['packingService']='0'  //包装服务，默认为否'0'
					})
					this.calculateCarriageFee(find.id)
				})
			},
			//展开&收缩物品信息
			spreadAndShrink(){
				this.spread=!this.spread
			},
			//新增物品
			addGoods(){
				// uni.navigateTo({
				// 	url:'/pages-operation/operation/addWaybill/addGoods'
				// })
				let district={
					shipDistrictName:this.formData.shipDistrictName,
					shipAddress:this.formData.shipAddress,
					deliveryDistrictName:this.formData.deliveryDistrictName,
					deliveryAddress:this.formData.deliveryAddress
				}
				uni.navigateTo({
					url:'/pages-operation/operation/addWaybill/addGoods?district='+JSON.stringify(district)
				})
			},
			//编辑物品
			editGoodsList(index){
				let district={
					shipDistrictName:this.formData.shipDistrictName,
					shipAddress:this.formData.shipAddress,
					deliveryDistrictName:this.formData.deliveryDistrictName,
					deliveryAddress:this.formData.deliveryAddress
				}
				uni.navigateTo({
					url:'/pages-operation/operation/addWaybill/addGoods?goodsDetails='+JSON.stringify(this.formData.goodSourceList[index])+'&index='+index+'&district='+JSON.stringify(district)
				})
			},
			//删除物品
			deleteGoodsList(index){
				let that = this
				uni.showModal({
					title: '提示',
					content: '确定删除此物品？',
					success: function (res) {
						if (res.confirm) {
							that.formData.goodSourceList.splice(index,1)
							that.calculate()  //计算总运费、总包装费
						}
					}
				});
			},
			//接收文件传递的id字符串集合
			getFileIdString_outboundAttach(fileIds){
				this.formData.outboundAttach=fileIds
			},
			//接收文件传递的id字符串集合
			getFileIdString_billAttach(fileIds){
				this.formData.billAttach=fileIds
			},
			//控货
			checkboxChange(e){
				if(e.detail.value.length!==0)
				{
					this.formData.cargoControl='1';  //控货
				}
				else
				{
					this.formData.cargoControl='0';  //非控货
				}
			},
			parseTime(time) {
			   let dateee = new Date(time).toJSON();
			   let date = new Date(+new Date(dateee)+8*3600*1000).toISOString().replace(/T/g,' ').replace(/\.[\d]{3}Z/,'')  
			   return date
			},
			//设置计划提货时间
			onStartTime(e){
				this.$set(this.formData, 'shipPlanTime', e ? (e+':'+new Date().getSeconds()) : '')
				this.$set(this.formData, 'deliveryPlanTime', e ? this.parseTime(new Date(e).setHours(new Date(e).getHours() + 2)) : '')
			},
			// 格式化开始与结束时间
			resetTime(shipPlanTime, deliveryPlanTime) {
			  const newTime = new Date()
			  newTime.setHours(newTime.getHours() + 2)
		
			  if (!shipPlanTime || new Date(shipPlanTime).getTime() < new Date().getTime()) {
			    shipPlanTime = this.parseTime(new Date().getTime())
			    deliveryPlanTime = this.parseTime(newTime)
			  }
			  if (!deliveryPlanTime || new Date(deliveryPlanTime).getTime() - new Date(shipPlanTime).getTime() < 1000 * 60 * 60 * 2) {
			    let date2 = new Date(shipPlanTime)
			    date2.setHours(date2.getHours() + 2)
			    deliveryPlanTime = this.parseTime(date2)
			  }
			  return {
			    shipPlanTime,
			    deliveryPlanTime
			  }
			},
			//增值服务弹出
			bindPickerChangeIncrementService(){
				uni.navigateTo({
					url:'/pages-operation/operation/addWaybill/waybillValueAdd?waybillValueAdd='+JSON.stringify(this.formData.waybillValueAdd)
				})
			},
			//消费抵扣弹出
			// bindPickerChangeConsumeDeduction(e){
			// 	this.index_consumeDeduction = e.detail.value
			// 	this.formData.consumeDeduction=this.array_consumeDeduction[this.index_consumeDeduction]
			// },
			//结算方式弹出
			// bindPickerChangeConsumeDeduction(e){
			// 	this.index_settlement = e.detail.value
			// 	this.formData.settlement=this.array_settlement[this.index_settlement]
			// },
			//运价说明
			tips(){
				this.$refs.popup.open()
			},
			//下单弹窗
			dialogToggle() {
				if(this.formData.goodSourceList.length===0)
				{
					uni.showToast({
						title: '请至少添加1个物品',
						icon:'none'
					})
					return
				}
				if(!this.waybillFee.settlementMode||this.waybillFee.settlementMode=='0')
				{
					uni.showToast({
						title: '结算方式不能为空',
						icon:'none'
					})
					return
				}
				if(!this.formData.shipPlanTime)
				{
					uni.showToast({
						title: '计划提货时间不能为空',
						icon:'none'
					})
					return
				}
				if(!this.formData.deliveryPlanTime)
				{
					uni.showToast({
						title: '计划到达时间不能为空',
						icon:'none'
					})
					return
				}
				if(this.moreSetting)  //打开了更多设置
				{
					if(!this.formData.waybillCarrier.driverName)
					{
						uni.showToast({
							title: '司机不能为空',
							icon: 'none'
						})
						return
					}
					if(!this.formData.waybillCarrier.driverCardId)
					{
						uni.showToast({
							title: '身份证号不能为空',
							icon:'none'
						})
						return
					}
					if(!this.formData.waybillCarrier.driverCardTel)
					{
						uni.showToast({
							title: '司机电话不能为空',
							icon:'none'
						})
						return
					}
					if(!this.formData.waybillCarrier.driverCarId)
					{
						uni.showToast({
							title: '车牌号不能为空',
							icon:'none'
						})
						return
					}
					if(!this.formData.waybillCarrier.vehicle)
					{
						uni.showToast({
							title: '车型不能为空',
							icon:'none'
						})
						return
					}
					if(!this.formData.waybillCarrier.energyType)
					{
						uni.showToast({
							title: '油品类型不能为空',
							icon:'none'
						})
						return
					}
				}
				this.$refs.alertDialog.open()
			},
			//修改运单
			updateWayBillProfile(){
				this.$refs.form.validate().then(res => {
					// if(!this.formData.waybillType)
					// {
					// 	uni.showToast({
					// 		title: '运单类型不能为空',
					// 		icon:'none'
					// 	})
					// 	return
					// }
					if(this.formData.goodSourceList.length===0)
					{
						uni.showToast({
							title: '请至少添加1个物品',
							icon:'none'
						})
						return
					}
					if(!this.waybillFee.settlementMode)
					{
						uni.showToast({
							title: '结算方式不能为空',
							icon:'none'
						})
						return
					}
					
					//交易总价 &&应付总价
					this.formData.tradeTotalFee=this.totalPrice
					this.formData.payableTotalFee=this.totalPrice
					
					uni.showLoading({
						title: '正在保存...',
					})
					updateWayBillProfile(this.formData).then(res => {
						uni.hideLoading()
						if (res.code == '200') {
							//新增成功后，删除本地草稿数据
							//uni.removeStorageSync('waybillDraft');
							uni.showToast({
								title: '保存成功',
								icon: 'none'
							})
							let pages = getCurrentPages(); // 获取当前页面栈的实例，以数组形式按栈的顺序给出，第一个元素为首页，最后一个元素为当前页面。
							let nowPage = pages[pages.length - 1]; //当前页页面实例
							let prevPage = pages[pages.length - 2]; //上一页页面实例
							prevPage.$vm.otherFun('0') // 給上一頁綁定方法otherFun,傳參0（tabIndex：0）
							uni.navigateBack({
								delta: 1 // 可以不傳delta值，默認為1
							})
						} else {
							uni.showToast({
								icon: 'none',
								title: res.msg
							})
						}		
					})
				}).catch(err => {
					uni.showToast({
						title: err[0].errorMessage,
						icon: 'none'
					})
				})
			},
			//点击保存自动提交为'待提交'状态
			autoConfirm() {
				this.$refs.form.validate().then(res => {
					// if(!isSupervisor)
					// {
					// 	uni.showToast({
					// 		title: '请在【服务人员】中设置一名主管',
					// 		icon:'none'
					// 	})
					// 	return
					// }
					
					
					
					uni.showLoading({
						title: '正在保存...',
					})
					this.formData.submitted='0'  //保存
					
					addWayBill(this.formData).then(res => {
						uni.hideLoading()
						if (res.code == '200') {
							//新增成功后，删除本地草稿数据
							//uni.removeStorageSync('waybillDraft');
							uni.showToast({
								title: '保存成功',
								icon: 'none'
							})
							let pages = getCurrentPages(); // 获取当前页面栈的实例，以数组形式按栈的顺序给出，第一个元素为首页，最后一个元素为当前页面。
							let nowPage = pages[pages.length - 1]; //当前页页面实例
							let prevPage = pages[pages.length - 2]; //上一页页面实例
							prevPage.$vm.otherFun('0','order') // 給上一頁綁定方法otherFun,傳參0（tabIndex：0）
							uni.navigateBack({
								delta: 1 // 可以不傳delta值，默認為1
							})
						} else {
							uni.showToast({
								icon: 'none',
								title: res.msg
							})
						}	
					})	
				}).catch(err => {
					uni.showToast({
						title: err[0].errorMessage,
						icon: 'none'
					})
				})
			},
			//确认下单
			async dialogConfirm() {
				// if(!this.formData.waybillType)
				// {
				// 	uni.showToast({
				// 		title: '运单类型不能为空',
				// 		icon:'none'
				// 	})
				// 	return
				// }
				
				//交易总价 &&应付总价
				this.formData.tradeTotalFee=this.totalPrice
				this.formData.payableTotalFee=this.totalPrice
				uni.showLoading({
					title: '正在提交...',
				})
				
				if(this.waybillId=='')  //第一次下单
				{
					this.formData.submitted='1'  //提交
					//加入调度单
					if(this.scheduleList.length!=0&&this.scheduleVo.scheduleNo) //如果当前已经选择调度车次信息
					{
						this.formData.scheduleNo=this.scheduleVo.scheduleNo
						this.formData.scheduleStatus='400'
						this.formData.scheduleVo=this.scheduleVo
					}
					await addWayBill(this.formData).then(res => {
						uni.hideLoading()
						if (res.code == '200') {
							//新增成功后，删除本地草稿数据
							//uni.removeStorageSync('waybillDraft');
							
							//加入调度单
							if(this.scheduleList.length!=0&&this.scheduleVo.scheduleNo) //如果当前已经选择调度车次信息
							{
								let form=JSON.parse(JSON.stringify(this.scheduleVo))
								form.carJson=form.carVo
								form.driverJson=form.driverVo
								let waybillIds=form.waybillList.map(item=>item.waybillId)
								waybillIds.push(res.data.waybillId)
								updateSchedule({waybillIds:waybillIds,...form}).then(res2=>{
									if(res2.code == '200')
									{
										uni.showToast({
											title: '加入调度车次成功',
											icon: 'none'
										})
									}
									else
									{
										uni.showToast({
											title: '加入调度车次失败',
											icon: 'none'
										})
									}
								})
							}
							else  //没有加入调度单
							{
								if(this.moreSetting)  //打开了更多设置
								{
									const { shipNetId, deliveryNetId, shipDistrictId, shipAddress, shipLng, shipLat, deliveryDistrictId, deliveryAddress, deliveryLng, deliveryLat } = res.data
									let params = {
									    driverJson: {
									        phoneNumber: this.formData.waybillCarrier.driverCardTel,
									        idCardNo: this.formData.waybillCarrier.driverCardId,
									        driverName: this.formData.waybillCarrier.driverName,
									        driverId: this.formData.waybillCarrier.driverId,
									    },
									    carrierId: this.formData.waybillCarrier.carrierObjectId || '',
									    carJson: {
									        carType: this.formData.waybillCarrier.vehicle,
									        licensePlate: this.formData.waybillCarrier.driverCarId,
									        carId: this.formData.waybillCarrier.carId,
											energyType:this.formData.waybillCarrier.energyType
									    },
									    waybillIds: [res.data.waybillId],
									    flowStatus: '400',
									    shipNetId,
									    deliveryNetId,
									    shipDistrictId,
									    shipAddress,
									    shipLng,
									    shipLat,
									    deliveryDistrictId,
									    deliveryAddress,
									    deliveryLng,
									    deliveryLat,
									    escortor: this.formData.waybillCarrier.escortor,
									    escortorPhone: this.formData.waybillCarrier.escortorPhone,
									    escortorldcard: this.formData.waybillCarrier.escortorldcard,
									    estPickupTime:this.formData.shipPlanTime,
									    estArriveTime:this.formData.deliveryPlanTime
									}
									addSchedule({...params,deptId: res.data.deptId}).then(res2 => {
										if (res2.code == '200') {
											uni.showToast({
												title: '调度成功',
												icon: 'none'
											})
										} else {
											uni.showToast({
												icon: 'none',
												title: res2.msg
											})
										}
									})
								}
							}
							uni.showToast({
								title: '提交成功',
								icon: 'none'
							})
							let pages = getCurrentPages(); // 获取当前页面栈的实例，以数组形式按栈的顺序给出，第一个元素为首页，最后一个元素为当前页面。
							let nowPage = pages[pages.length - 1]; //当前页页面实例
							let prevPage = pages[pages.length - 2]; //上一页页面实例
							prevPage.$vm.otherFun('0','order') // 給上一頁綁定方法otherFun,傳參0（tabIndex：0）
							uni.navigateBack({
								delta: 1 // 可以不傳delta值，默認為1
							})
						} else {
							uni.showToast({
								icon: 'none',
								title: res.msg
							})
						}		
					})
				}
				else  //第二次下单,先保存，后提交
				{
					//修改保存
					
					//加入调度单
					if(this.scheduleList.length!=0&&this.scheduleVo.scheduleNo) //如果当前已经选择调度车次信息
					{
						this.formData.scheduleNo=this.scheduleVo.scheduleNo
						this.formData.scheduleStatus='400'
						this.formData.scheduleVo=this.scheduleVo
					}
					await updateWayBillProfile(this.formData).then(res => {
						uni.hideLoading()
						if (res.code == '200') {
							//提交
							updateWayBillStatus(110,this.waybillId).then(res_ => {
								uni.hideLoading()
								if (res_.code == '200') {
									//新增成功后，删除本地草稿数据
									//uni.removeStorageSync('waybillDraft');
									
									//加入调度单
									if(this.scheduleList.length!=0&&this.scheduleVo.scheduleNo) //如果当前已经选择调度车次信息
									{
										let form=JSON.parse(JSON.stringify(this.scheduleVo))
										form.carJson=form.carVo
										form.driverJson=form.driverVo
										let waybillIds=form.waybillList.map(item=>item.waybillId)
										waybillIds.push(this.waybillId)
										updateSchedule({waybillIds:waybillIds,...form}).then(res2=>{
											if(res2.code == '200')
											{
												uni.showToast({
													title: '加入调度车次成功',
													icon: 'none'
												})
											}
											else
											{
												uni.showToast({
													title: '加入调度车次失败',
													icon: 'none'
												})
											}
										})
									}
									else  //没有加入调度单
									{
										if(this.moreSetting)  //打开了更多设置
										{
											const { shipNetId, deliveryNetId, shipDistrictId, shipAddress, shipLng, shipLat, deliveryDistrictId, deliveryAddress, deliveryLng, deliveryLat } = res.data
											let params = {
											    driverJson: {
											        phoneNumber: this.formData.waybillCarrier.driverCardTel,
											        idCardNo: this.formData.waybillCarrier.driverCardId,
											        driverName: this.formData.waybillCarrier.driverName,
											        driverId: this.formData.waybillCarrier.driverId,
											    },
											    carrierId: this.formData.waybillCarrier.carrierObjectId || '',
											    carJson: {
											        carType: this.formData.waybillCarrier.vehicle,
											        licensePlate: this.formData.waybillCarrier.driverCarId,
											        carId: this.formData.waybillCarrier.carId,
													energyType:this.formData.waybillCarrier.energyType
											    },
											    waybillIds: [res.data.waybillId],
											    flowStatus: '400',
											    shipNetId,
											    deliveryNetId,
											    shipDistrictId,
											    shipAddress,
											    shipLng,
											    shipLat,
											    deliveryDistrictId,
											    deliveryAddress,
											    deliveryLng,
											    deliveryLat,
											    escortor: this.formData.waybillCarrier.escortor,
											    escortorPhone: this.formData.waybillCarrier.escortorPhone,
											    escortorldcard: this.formData.waybillCarrier.escortorldcard,
											    estPickupTime:this.formData.shipPlanTime,
											    estArriveTime:this.formData.deliveryPlanTime
											}
											addSchedule({...params,deptId: res.data.deptId}).then(res2 => {
												if (res2.code == '200') {
													uni.showToast({
														title: '调度成功',
														icon: 'none'
													})
												} else {
													uni.showToast({
														icon: 'none',
														title: res2.msg
													})
												}
											})
										}
									}
									uni.showToast({
										title: '提交成功',
										icon: 'none'
									})
									let pages = getCurrentPages(); // 获取当前页面栈的实例，以数组形式按栈的顺序给出，第一个元素为首页，最后一个元素为当前页面。
									let nowPage = pages[pages.length - 1]; //当前页页面实例
									let prevPage = pages[pages.length - 2]; //上一页页面实例
									prevPage.$vm.otherFun('0','order') // 給上一頁綁定方法otherFun,傳參0（tabIndex：0）
									uni.navigateBack({
										delta: 1 // 可以不傳delta值，默認為1
									})
								} else {
									uni.showToast({
										icon: 'none',
										title: res_.msg
									})
								}	
							})
						} else {
							uni.showToast({
								icon: 'none',
								title: res.msg
							})
						}
								
					})
				}
			},
			
		},
	}
</script>

<style scoped>
.buttonHover {
		opacity: 0.6;
	}
	::v-deep .uni-border-left{
	    border-left-color: #f0f0f0;
	    border-left-style: solid;
	    border-left-width: 1px;
	    background-color: rgb(157,81,38);
	    border-radius: 0 0 11px 0;
	    /* color: white; */
	}
	
	::v-deep .uni-button-color{
	    color: #ffffff;
	}
	
	::v-deep .uni-select__input-box{
		width: 0vw;
	}
	
	::v-deep .file-title{
	    font-size: 12px;
	    color: #333;
	}
</style>